package util

import (
	//	"fmt"
	"math/rand"
	"strings"
	"time"
)

// RandStringRunes 返回随机字符串
func RandStringRunes(n int) string {
	var letterRunes = []rune("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

	rand.Seed(time.Now().UnixNano())
	b := make([]rune, n)
	for i := range b {
		b[i] = letterRunes[rand.Intn(len(letterRunes))]
	}
	return string(b)
}

func GetDate() string {
	date := time.Now().Local().Format("2006-01-02 15:04:05")
	return date
}
func FormatDate(times string) string {
	date := strings.Replace(times, "T", " ", 1)
	date = strings.Replace(date, "+08:00", "", 1)
	return date
}

func GetTime(times string) int64 {
	create_time, err := time.ParseInLocation("2006-01-02 15:04:05", times, time.Local) //这里按照当前时区转
	//create_time, err := time.Parse("2006-01-02 15:04:05", times)
	if err != nil {
		panic(err)
	}
	return create_time.Unix()
}

func GetTimeSql(times string) int64 {
	create_time, err := time.ParseInLocation("2006-01-02T15:04:05+08:00", times, time.Local) //这里按照当前时区转
	if err != nil {
		panic(err)
	}
	return create_time.Unix()
}
